package com.atstudy.list;

import java.util.LinkedList;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/3 10:49
 * @copyright: 博为峰
 */
public class LinkedListDemo {
    public static void main(String[] args) {
//        m1();
        LinkedList linkedList = new LinkedList();

        linkedList.addFirst("a");
        linkedList.addFirst("b");
        linkedList.addLast("c");

        linkedList.offerFirst("d");
        linkedList.offerLast("e");

//        m2(linkedList);

//        m3(linkedList);

        System.out.println(linkedList);
    }

    private static void m3(LinkedList linkedList) {
        System.out.println(linkedList.getFirst());//如果链表为空，抛NoSuchElementException
        System.out.println(linkedList.getLast());

        System.out.println(linkedList.peekFirst());//如果链表为空，返回null
        System.out.println(linkedList.peekLast());
    }

    //删
    private static void m2(LinkedList linkedList) {
        linkedList.removeFirst();//如果链表为空，抛NoSuchElementException
        linkedList.removeLast();

        linkedList.pollFirst();//如果链表为空，返回null
        linkedList.pollLast();
    }

    //增
    private static void m1() {
        LinkedList linkedList = new LinkedList();

        linkedList.addFirst("a");
        linkedList.addFirst("b");
        linkedList.addLast("c");

        linkedList.offerFirst("d");
        linkedList.offerLast("e");
        System.out.println(linkedList);
    }
}
